<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="db.Purreq"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.PurreqDAO"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="db.User"%>
<%@page import="db.UserDAO"%>
<%@page import="db.PurmatDAO"%>
<%@page import="db.Purmat"%>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	PurreqDAO purreqDao = (PurreqDAO)ctx.getBean("PurreqDAO");
	UserDAO userDao = (UserDAO)ctx.getBean("UserDAO");
	PurmatDAO purmatDao = (PurmatDAO)ctx.getBean("PurmatDAO");

	String purreqId = request.getParameter("purreqId");
	String idPar = request.getParameter("id");
	String[] idsPar = request.getParameterValues("serial");
	
	request.setAttribute("purreqId",purreqId);
	
	int uid = (Integer)session.getAttribute("id");
	
	int id = 0;
	
	try{
		id = Integer.parseInt(idPar);
	}catch(Exception e){
		id = 0;
	}
	
	Purreq purreq = purreqDao.findById(id);
	request.setAttribute("purreq",purreq);
	
	List list = new ArrayList();
	for(int i=0;i<idsPar.length;i++){
		 Purmat purmat = purmatDao.findById(Integer.parseInt(idsPar[i]));
		 list.add(purmat);
	}
	
	request.setAttribute("parmats",list);
	
	User reqUser = userDao.findById(purreq.getReqUserId());
	request.setAttribute("reqUser",reqUser);
	
	User buyUser = userDao.findById(uid);
	request.setAttribute("buyUser",buyUser);
	
	request.setAttribute("tmpCode","L" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
	
	pageContext.forward("/vm/procure/procureApp_4.vm");
%>